from django import forms
from django.contrib.admin import ModelAdmin

from app.models import FMUser
from app.models.fm_user import USER_TYPE_SALES
from app.models.invitation_code import InvitationCode


class InvitationCodeForm(forms.ModelForm):
    sales = forms.ModelChoiceField(queryset=FMUser.objects.filter(user_type=USER_TYPE_SALES))

    class Meta:
        model = InvitationCode
        fields = ('sales', 'code')


class InvitationCodeAdmin(ModelAdmin):
    add_form = InvitationCodeForm
    form = InvitationCodeForm
    list_display = ('id', 'sales', 'code')
    list_filter = ('sales__sales_area',)
